import request from './useRequests';
import { userinfo } from '@/stores/counter';
import { ElMessage } from 'element-plus';
import { useRoute, useRouter } from 'vue-router';

export default function uselogout() {
  const router = useRouter();
  const user = userinfo();
  async function logout() {
    ElMessage({
      showClose: true,
      message: '已退出',
      type: 'success',
    });
    // user.signup = false;
    user.usercardPage = 0;
    user.login = false;
    user.baseInfo = {
      id: NaN,
      username: '',
      telephone: '',
      token: '',
      avator: '',
      sex: '',
      mail: '',

      // address: '', //区域
      // career: '',
      // status: NaN,
    };

    localStorage.removeItem('id');
    localStorage.removeItem('username');
    localStorage.removeItem('telephone');
    localStorage.removeItem('token');
    localStorage.removeItem('avator');
    localStorage.removeItem('sex');
    localStorage.removeItem('mail');

    router.push('/');

    // request.delete('/user/logout')
    //   .then(res => {
    //     // console.log(res)
    //     if (res.data.success == true) {
    //       ElMessage({
    //         showClose: true,
    //         message: '已退出',
    //         type: 'success',
    //       })
    //       user.signup = false;
    //       user.login = false;
    //       user.baseInfo = {
    //         id: '',
    //         address: '',//区域
    //         career: '',
    //         nickname: '',
    //         telephone: '',
    //         status: NaN
    //       }
    //     }
    //     else {
    //       ElMessage({
    //         showClose: true,
    //         message: `${res.data.message}`,
    //         type: 'error',
    //       })
    //     }
    //   })
  }

  return {
    logout,
  };
}
